package org.shuma.supplier.controller;

import org.shuma.supplier.domain.dto.SupplierDTO;
import com.shuma.domain.pojo.Result;
import lombok.extern.slf4j.Slf4j;
import org.shuma.supplier.service.SupplierService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;

/**
 * @author :Wjh
 * @since :2024/6/17 上午11:37
 */

@Slf4j
@Validated
@RestController
@RequestMapping("/supplier")
@CrossOrigin
public class SupplierController {

    @Autowired
    private SupplierService supplierService;

    /**
     * 根据供应商id获取供应商信息
     * @param supplierId 供应商id
     * @return 供应商信息
     */
    @GetMapping("/get_supplier")
    public Result getSupplier(@RequestParam @NotNull Integer supplierId,
                              @RequestHeader("Authorization") @NotNull(message = "token不能为空") String token) {
        return supplierService.getSupplier(supplierId,token);
    }

    /**
     * 添加供应商
     * @param supplierDTO 供应商名字和电话
     * @return 添加结果
     */
    @PostMapping("/add_supplier")
    public Result addSupplier(@RequestBody @Validated SupplierDTO supplierDTO,
                              @RequestHeader("Authorization") @NotNull(message = "token不能为空") String token) {
        return supplierService.addSupplier(supplierDTO,token);
    }

    /**
     * 删除供应商信息
     * @param supplierId 供应商id
     * @return 删除结果
     */
    @DeleteMapping("/supplier")
    public Result deleteSupplier(@RequestParam @NotNull Integer supplierId,
                                 @RequestHeader("Authorization") @NotNull(message = "token不能为空") String token) {
        return supplierService.deleteSupplier(supplierId,token);
    }
}
